/*
#include "reg52.h"
#include "intrins.h"


sbit LeftCon1A = P2^0;
sbit LeftCon1B = P2^1;

sbit RightCon1A = P2^2;
sbit RightCon1B = P2^3;


void goForward()
{
	LeftCon1A = 1;
	LeftCon1B = 0;
	
	RightCon1A = 1;
	RightCon1B = 0;
}

void goBack()
{
	LeftCon1A = 0;
	LeftCon1B = 1;
	
	RightCon1A = 0;
	RightCon1B = 1;
}

void goLeft()
{
	LeftCon1A = 0;
	LeftCon1B = 0;
	
	RightCon1A = 1;
	RightCon1B = 0;
}

void goRight()
{
	LeftCon1A = 1;
	LeftCon1B = 0;
	
	RightCon1A = 0;
	RightCon1B = 0;
}

void stop()
{
	LeftCon1A = 0;
	LeftCon1B = 0;
	
	RightCon1A = 0;
	RightCon1B = 0;
}
*/
#include "reg52.h"

sbit LeftCon1A = P2^0;
sbit LeftCon1B = P2^1;
sbit RightCon1A = P2^2;
sbit RightCon1B = P2^3;

void delayMicroseconds(unsigned int us)
{
    while(us--);
}
void setMotorSpeeds(unsigned char leftSpeed, unsigned char rightSpeed, bit leftForward, bit rightForward)
{
    unsigned char i;
    for(i = 0; i < 100; i++)
    {
        // 控制左电机
        if(i < leftSpeed)
        {
            if(leftForward)
            {
                LeftCon1A = 1;
                LeftCon1B = 0;
            }
            else
            {
                LeftCon1A = 0;
                LeftCon1B = 1;
            }
        }
        else
        {
            LeftCon1A = 0;
            LeftCon1B = 0;
        }

        // 控制右电机
        if(i < rightSpeed)
        {
            if(rightForward)
            {
                RightCon1A = 1;
                RightCon1B = 0;
            }
            else
            {
                RightCon1A = 0;
                RightCon1B = 1;
            }
        }
        else
        {
            RightCon1A = 0;
            RightCon1B = 0;
        }

        delayMicroseconds(20);  // 调整此值以控制PWM频率
    }
}